package com.wlps.controller;

import com.wlps.service.*;
import com.wlps.vo.sendcenter.commodity.CommodityAddVo;
import com.wlps.vo.sendcenter.commodity.CommodityConditionVo;
import com.wlps.vo.sendcenter.commodity.CommodityUpdateVo;
import com.wlps.vo.sendcenter.commodity.FirstClassificationVo;
import com.wlps.vo.sendcenter.inoutform.CommodityAndWarehouseVo;
import com.wlps.vo.sendcenter.inoutform.CommodityInOutConditionVo;
import com.wlps.vo.sendcenter.inoutform.PurchaseReceiptAddVo;
import com.wlps.vo.sendcenter.inoutform.ReturnOutOfStockAddVo;
import com.wlps.vo.sendcenter.statistics.CommodityStatisticsVo;
import com.wlps.vo.sendcenter.supplier.*;
import com.wlps.entity.*;
import com.wlps.result.ResultPageVo;
import com.wlps.result.ResultVo;
import com.wlps.service.function.AbstractController;
import com.wlps.vo.sendcenter.warehouse.*;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 配送中心
 * </p>
 *
 * @author ZWYZY
 * @since 2020/7/31
 */
@RestController
@RequestMapping("/api/send")
@Slf4j
@Validated
@Api(tags = "配送中心", description = "")
public class SendCenter extends AbstractController {
    @Override
    public boolean judgeHasCommodity(long id) {
        return false;
    }

    @Override
    public Order generateOrder(Client client, long id) {
        return null;
    }

    public void dealWithOrder(Order order) {
    }

    @Autowired
    ISupplierService supplierService;

    @Autowired
    IWarehouseService warehouseService;

    @Autowired
    IPurchaseReceiptService purchaseReceiptService;

    @Autowired
    IReturnOutOfStockService returnOutOfStockService;

    @Autowired
    ICommodityWarehouseService commodityWarehouseService;

    @Autowired
    ICommodityService commodityService;

    @Autowired
    IFirstClassificationService firstClassificationService;

    @Autowired
    ISecondClassificationService secondClassificationService;

    @GetMapping("/getSupplier")
    @ApiOperation(value = "分页显示供应商")
    public ResultPageVo<List<Supplier>> getSupplier(

            @ApiParam(value = "页数号（默认1）")
            @RequestParam(required = false, defaultValue = "1") int pageNum,
            @ApiParam(value = "页条数（默认10）")
            @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "排序（默认为true）")
            @RequestParam(required = false, defaultValue = "true") boolean sort,
            @ApiParam(value = "供应商名字")
            @RequestParam(required = false) String name
//            @RequestBody(required = false) CombineQueryVo combineQueryVo,

    ) {

        return supplierService.getSupplier(pageNum, pageSize, name);
    }

    @PostMapping("/addSupplier")
    @ApiOperation(value = "增加供应商")
    public ResultVo addSupplier(@Validated @RequestBody SupplierAddVo supplierAddVo) {
        return supplierService.addSupplier(supplierAddVo);
    }

    @GetMapping("/deleteSupplier")
    @ApiOperation(value = "删除供应商")
    public ResultVo deleteSupplier(@NotNull(message = "供应商id不能为空") @ApiParam(value = "供应商id", required = true) @RequestParam(required = false) Long id) {
        return supplierService.deleteSupplier(id);
    }

    @PostMapping("/updateSupplier")
    @ApiOperation(value = "更改供应商")
    public ResultVo updateSupplier(@Validated @RequestBody SupplierUpdateVo supplierUpdateVo) {
        return supplierService.updateSupplier(supplierUpdateVo);
    }

    @GetMapping("/getSupplierById")
    @ApiOperation(value = "根据id查询供应商")
    public ResultVo<Supplier> getSupplierById(@NotNull(message = "供应商id不能为空") @ApiParam(value = "供应商id", required = true) @RequestParam(required = false) Long id) {
        return supplierService.getSupplierById(id);
    }

    @GetMapping("/getWarehouse")
    @ApiOperation(value = "分页显示库房")
    public ResultPageVo<List<Warehouse>> getWarehouse(
            @ApiParam(value = "页数号（默认1）")
            @RequestParam(required = false, defaultValue = "1") int pageNum,
            @ApiParam(value = "页条数（默认10）")
            @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "排序（默认为true）")
            @RequestParam(required = false, defaultValue = "true") boolean sort,
            @ApiParam(value = "库房名字")
            @RequestParam(required = false) String name
    ) {

        return warehouseService.getWarehouse(pageNum, pageSize, name);
    }

    @PostMapping("/addWarehouse")
    @ApiOperation(value = "增加库房")
    public ResultVo addWarehouse(@Validated @RequestBody WarehouseAddVo warehouseAddVo) {
        return warehouseService.addWarehouse(warehouseAddVo);
    }

    @GetMapping("/deleteWarehouse")
    @ApiOperation(value = "删除库房")
    public ResultVo deleteWarehouse(@NotNull(message = "库房id不能为空") @ApiParam(value = "库房id", required = true) @RequestParam(required = false) Long id) {
        return warehouseService.deleteWarehouse(id);
    }

    @PostMapping("/updateWarehouse")
    @ApiOperation(value = "更改库房")
    public ResultVo updateWarehouse(@Validated @RequestBody WarehouseUpdateVo warehouseUpdateVo) {
        return warehouseService.updateWarehouse(warehouseUpdateVo);
    }

    @GetMapping("/getWarehouseById")
    @ApiOperation(value = "根据id查询库房")
    public ResultVo<Warehouse> getWarehouseById(@NotNull(message = "库房id不能为空") @ApiParam(value = "库房id", required = true) @RequestParam(required = false) Long id) {
        return warehouseService.getWarehouseById(id);
    }

    @PostMapping("/getCommodity")
    @ApiOperation(value = "分页显示商品")
    public ResultPageVo<List<Commodity>> getCommodity(
            @ApiParam(value = "页数号（默认1）")
            @RequestParam(required = false, defaultValue = "1") int pageNum,
            @ApiParam(value = "页条数（默认10）")
            @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "排序（默认为true）")
            @RequestParam(required = false, defaultValue = "true") boolean sort,
//            @RequestParam(required = false) String name,
            @ApiParam(value = "商品组合查询对象")
            @RequestBody(required = false) CommodityConditionVo commodityConditionVo

    ) {

        return commodityService.getCommodity(pageNum, pageSize, commodityConditionVo);
    }

    @PostMapping("/addCommodity")
    @ApiOperation(value = "增加商品")
    public ResultVo addCommodity(@Validated @RequestBody CommodityAddVo commodityAddVo) {
        return commodityService.addCommodity(commodityAddVo);
    }

    @GetMapping("/deleteCommodity")
    @ApiOperation(value = "删除商品")
    public ResultVo deleteCommodity(@NotNull(message = "商品id不能为空") @ApiParam(value = "商品id", required = true) @RequestParam(required = false) Long id) {
        return commodityService.deleteCommodity(id);
    }

    @PostMapping("/updateCommodity")
    @ApiOperation(value = "修改商品")
    public ResultVo updateCommodity(@ApiParam(value = "修改商品Vo", required = true) @Validated @RequestBody CommodityUpdateVo commodityAddVo) {
        return commodityService.updateCommodity(commodityAddVo);
    }

    @GetMapping("/addFirstClassification")
    @ApiOperation(value = "增加一级分类")
    public ResultVo addFirstClassification(@NotNull(message = "必须填一级分类名称") @NotBlank(message = "一级分类名称不能为空") @ApiParam(value = "一级分类名称", required = true) @RequestParam(required = false) String firstName) {
        return firstClassificationService.addFirstClassification(firstName);
    }

    @GetMapping("/addSecondClassification")
    @ApiOperation(value = "增加二级分类")
    public ResultVo addSecondClassification(@NotNull(message = "一级分类id不能为空") @ApiParam(value = "一级分类id", required = true) @RequestParam(required = false) Long firstId, @NotNull(message = "必须填二级分类名称") @NotBlank(message = "二级分类名称不能为空") @ApiParam(value = "二级分类名称") @RequestParam(required = false) String secondName) {
        return secondClassificationService.addSecondClassification(firstId, secondName);
    }

    @GetMapping("/getFirstClassification")
    @ApiOperation(value = "分页显示一级分类")
    public ResultPageVo<List<FirstClassificationVo>> getFirstClassification(
            @ApiParam(value = "页数号（默认1）")
            @RequestParam(required = false, defaultValue = "1") int pageNum,
            @ApiParam(value = "页条数（默认10）")
            @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "排序（默认为true）")
            @RequestParam(required = false, defaultValue = "true") boolean sort,
            @ApiParam(value = "一级分类名称")
            @RequestParam(required = false) String firstName
    ) {

        return firstClassificationService.getFirstClassification(pageNum, pageSize, firstName);
    }
    @GetMapping("/getSecondClassificationList")
    public ResultVo<List<SecondClassification>> getSecondClassificationList(@RequestParam Long id){
       return secondClassificationService.getSecondClassificationList(id);
    }

    @GetMapping("/getWarehouseSettingVo")
    @ApiOperation(value = "分页显示商品库房储备设置")
    public ResultPageVo<List<WarehouseSettingVo>> getWarehouseSettingVo(
            @ApiParam(value = "页数号（默认1）")
            @RequestParam(required = false, defaultValue = "1") int pageNum,
            @ApiParam(value = "页条数（默认10）")
            @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "排序（默认为true）")
            @RequestParam(required = false, defaultValue = "true") boolean sort,
            @ApiParam(value = "商品名称")
            @RequestParam(required = false) String name
//            @RequestBody(required = false) CombineQueryVo combineQueryVo,

    ) {

        return commodityWarehouseService.getWarehouseSettingVo(pageNum, pageSize, name);
    }

    @PostMapping("/updateWarehouseSettingSaveOrUpdateVo")
    @ApiOperation(value = "增加/修改库房储备设置")
    public ResultVo updateWarehouseSettingSaveOrUpdateVo(@Validated @RequestBody WarehouseSettingSaveOrUpdateVo warehouseSettingSaveOrUpdateVo) {
        return commodityWarehouseService.updateWarehouseSettingSaveOrUpdateVo(warehouseSettingSaveOrUpdateVo);
    }

    @GetMapping("/getCurrentNumberVo")
    @ApiOperation(value = "分页显示商品库存量")
    public ResultPageVo<List<CurrentNumberVo>> getCurrentNumberVo(
            @ApiParam(value = "页数号（默认1）")
            @RequestParam(required = false, defaultValue = "1") int pageNum,
            @ApiParam(value = "页条数（默认10）")
            @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "排序（默认为true）")
            @RequestParam(required = false, defaultValue = "true") boolean sort,
            @ApiParam(value = "商品名称")
            @RequestParam(required = false) String name
    ) {

        return commodityWarehouseService.getCurrentNumberVo(pageNum, pageSize, name);
    }

    @PostMapping("/getInOutVo")
    @ApiOperation(value = "分页显示出入单")
    public ResultPageVo<List<InOutVo>> getInOutVo(
            @ApiParam(value = "页数号（默认1）")
            @RequestParam(required = false, defaultValue = "1") int pageNum,
            @ApiParam(value = "页条数（默认10）")
            @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "排序（默认为true）")
            @RequestParam(required = false, defaultValue = "true") boolean sort,
            @ApiParam(value = "出入单组合查询Vo")
            @RequestBody(required = false) InOutConditionVo inOutConditionVo
    ) {

        return commodityWarehouseService.getInOutVo(pageNum, pageSize, inOutConditionVo);
    }

    @PostMapping("/addPurchaseReceiptAddVo")
    @ApiOperation(value = "创建入库单")
    public ResultVo<PurchaseReceipt> addPurchaseReceiptAddVo(@Validated @RequestBody PurchaseReceiptAddVo purchaseReceiptAddVo) {
        return purchaseReceiptService.addPurchaseReceiptAddVo(purchaseReceiptAddVo);
    }

    @PostMapping("/addReturnOutOfStockAddVo")
    @ApiOperation(value = "创建出库单")
    public ResultVo<ReturnOutOfStock> addReturnOutOfStockAddVo(@Validated @RequestBody ReturnOutOfStockAddVo returnOutOfStockAddVo) {
        return returnOutOfStockService.addReturnOutOfStockAddVo(returnOutOfStockAddVo);
    }

    @PostMapping("/getCommodityAndWarehouseOutVo")
    @ApiOperation(value = "分页显示需出库商品")
    public ResultPageVo<List<CommodityAndWarehouseVo>> getCommodityAndWarehouseOutVo(
            @ApiParam(value = "页数号（默认1）")
            @RequestParam(required = false, defaultValue = "1") int pageNum,
            @ApiParam(value = "页条数（默认10）")
            @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "排序（默认为true）")
            @RequestParam(required = false, defaultValue = "true") boolean sort,
//            @RequestParam(required = false) String name,
            @ApiParam(value = "商品出库条件查询Vo")
            @RequestBody(required = false) CommodityInOutConditionVo commodityInOutConditionVo
//            @RequestBody(required = false) CombineQueryVo combineQueryVo,

    ) {

        return commodityService.getCommodityAndWarehouseOutVo(pageNum, pageSize, commodityInOutConditionVo);
    }
    @PostMapping("/getCommodityAndWarehouseInVo")
    @ApiOperation(value = "分页显示需入库商品")
    public ResultPageVo<List<CommodityAndWarehouseVo>> getCommodityAndWarehouseInVo(
            @ApiParam(value = "页数号（默认1）")
            @RequestParam(required = false, defaultValue = "1") int pageNum,
            @ApiParam(value = "页条数（默认10）")
            @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "排序（默认为true）")
            @RequestParam(required = false, defaultValue = "true") boolean sort,
//            @RequestParam(required = false) String name,
            @ApiParam(value = "商品入库条件查询Vo")
            @RequestBody(required = false) CommodityInOutConditionVo commodityInOutConditionVo
//            @RequestBody(required = false) CombineQueryVo combineQueryVo,

    ) {

        return commodityService.getCommodityAndWarehouseInVo(pageNum, pageSize, commodityInOutConditionVo);
    }

    @PostMapping("/getCommodityStatisticsVo")
    @ApiOperation(value = "商品订购排行榜")
    public ResultVo<List<CommodityStatisticsVo>> getCommodityStatisticsVo(

            @ApiParam(value = "起止时间", required = false) Date startTime, @ApiParam(value = "终止时间", required = false) Date endTime
    ) {

        return new ResultVo<>();
    }

}
